package onlinebanking.server.modules;

import onlinebanking.exceptions.UserNotLoggedInException;
import onlinebanking.network.Message;
import onlinebanking.server.ServerEngine;
import onlinebanking.server.objects.Announcement;

public class AnnouncementModule extends Module{
	
	public AnnouncementModule(ServerEngine se, Message message) {
		this.serverengine = se;
		this.message = message;
	}
	
	public Message handleRequest(){
		Message response = new Message();
		
		
		if (serverengine.isLoggedIn()) {
			//Include personal announcements 
			try {
				int personalaccountid = this.serverengine.getSession().getUserAccount().getpersonalaccountid();
				Message personal = Announcement.getPersonalAnnouncements(personalaccountid);
				
				return personal; //or dapat kasama pa ung general?
				
				
			} catch (UserNotLoggedInException e) {
				response.setAsUserNotLoggedIn();
				return response;
			}
		}else{
			Message general = Announcement.getGeneralAnnouncements();
			return general;
		}
	}

}
